
*******************************************
*** Program to Reweight Data 1986 (T=C) ***
*******************************************

clear
drop _all
set more off

// random number seed requires older version
version 12
*help whatsnew13to14
cd "$US_Ineq_Repl"
local Processed = "$US_Ineq_Repl/Processed"
local FFL = "$US_Ineq_Repl/Scripts/FFL"

// customize your file path
cd "`FFL'"
global data "`c(pwd)'\Data"

cd "`Processed'"
use "Data86-15.dta" , clear
gen time=0 if year==1986
replace time=1 if year==2015

*** make weights comparable across two periods ***

forvalues t=0/1 { 
	su orgwgt if time==`t'
	replace orgwgt=`r(N)'*orgwgt/`r(sum)' if time==`t'
	su orgwgt if time==`t'
}
***************************************************************************
preserve
	keep if time==0
	save $data\us86.dta , replace
restore

preserve
	keep if time==1
	save $data\us15.dta , replace
restore

*** probit for year effects ***
local lovs=""

forvalues d=2(1)5 {
	gen uned`d'=educ`d'*union
	local lovs="`lovs' "+"uned`d'"
}
forvalues d=2(1)5 {
	gen pubed`d'=educ`d'*pubsect
	local lovs="`lovs' "+"pubed`d'"
}
forvalues d=2(1)5 {
	gen marred`d'=educ`d'*married
	local lovs="`lovs' "+"marred`d'"
}
forvalues x=2(1)4 {
	gen unex`x'=expe`x'*union
	local lovs="`lovs' "+"unex`x'"
}
forvalues x=2(1)4 {
	gen pubex`x'=expe`x'*pubsect
	local lovs="`lovs' "+"pubex`x'"
}
forvalues x=2(1)4 {
	forvalues d=2(1)5 {
		gen ex`x'ed`d'=educ`d'*expe`x'
		local lovs="`lovs' "+"ex`x'ed`d'"
	}
}
forvalues in=2(1)20 {
	forvalues x=2(1)4 {
		gen indd`in'ex`x'=expe`x'*indu`in'
		local lovs="`lovs' "+"indd`in'ex`x'"
	}
}

di "`lovs'"

logistic time union pubsect manuf nonwhite female partte ///
   married educ2-educ5 expe2-expe4 indu2-indu20 /// 
   state1-state10 state12-state51 ///
   `lovs' [iweight=orgwgt]
predict py15, p
*Overlapping Support
replace py15=0.99 if py15>0.99

summ time [weight=orgwgt]
replace orgwgt=orgwgt*py15/(1-py15)*((1-`r(mean)')/`r(mean)') if time==0

drop `lovs'

keep if time==0
replace time=2

compress
save $data\us86rw15.dta , replace

